package com.tuzki.zhuogui.servlet;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.tuzki.zhuogui.core.Constants;
import com.tuzki.zhuogui.core.Utils;
import com.tuzki.zhuogui.data.MybatisUtil;

public class CreateRoomServlet extends HttpServlet {

	/**
	 * 
	 */
	private static final long serialVersionUID = -8003216865775521377L;

	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		String userId = request.getParameter(Constants.KEY_USER_ID);
		String nickName = request.getParameter(Constants.KEY_NICK_NAME);
		String roomNumber = Utils.generateRoomNumber();
		Map<String, String> map = new HashMap<String, String>();
		map.put("roomNumber", roomNumber);
		map.put("userId", userId);
		map.put("nickName", nickName);
		MybatisUtil.insert("zhuogui.createRoom", map);
		response.getWriter().write(roomNumber);
	
	}


}
